/*
Copyright 2007 Raymond Giorgi

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
 */

package edu.pitt.CS2510.NodeActions;

import java.util.ArrayList;

import edu.pitt.CS2510.Coordinate;
import edu.pitt.CS2510.Nodes.WorkerNode;

/**
 * 
 * @author NoOne
 * 
 *         This class defines all the actions a GruntNode can perform. It is
 *         instantiated when a worker node recieves a SetTypeMessage with an
 *         argument of '0' for its type
 */
public class GruntActions implements NodeActionsInterface {
	protected WorkerNode parent = null;

	/**
	 * Gives the class access to its parent
	 * 
	 * @param parent
	 */
	public GruntActions(WorkerNode parent) {
		this.parent = parent;
	}

	/**
	 * Tells the grunt to position itself at the location provided
	 */
	@Override
	public void processAttackMessage(Coordinate co) {
		parent.setCoordinate(co);
	}

	/**
	 * If the system is performing correctly, this method should not be called.
	 * Useful in debugging
	 */
	@Override
	public void processDoneMessage(int from, ArrayList<Integer> nodes) {
		System.err.println("This method should not be called for a grunt node:"
				+ "processDoneMessage()");
	}

	/**
	 * When the supervisor thinks that this Grunt is finished attacking it sends
	 * a message that activates this. Changes all variables back to its 'idle'
	 * state.
	 */
	@Override
	public void processQuitMessage() {
		parent.setCoordinate(null);
		parent.release();
	}

	/**
	 * If the system is performing correctly, this method should not be called.
	 * Useful in debugging
	 */
	@Override
	public void processRequestMessage(int from, int no) {
		// TODO Auto-generated method stub

	}

	/**
	 * If the system is performing correctly, this method should not be called.
	 * Useful in debugging
	 */
	@Override
	public void processSupplyMessage(ArrayList<Integer> list) {
		// TODO Auto-generated method stub

	}

	/**
	 * If the system is performing correctly, this method should not be called.
	 * Useful in debugging
	 */
	public void processUpdateMessage(ArrayList<Coordinate> list, int from) {
		System.out.println("This method should not be called for a grunt node:"
				+ "processUpdateMessage()");
	}

	/**
	 * Tells the parent to change its type to nothing. At the next cycle it will
	 * change its messageHandler type to 'null'
	 */
	protected void release() {
		parent.setType(-1);
	}

	@Override
	public void updateGrid(ArrayList<Coordinate> coordinates) {

	}
}
